Repository navigation
Follow the project directory a push renames in cloud commands - #734
quantconnect-kronos[bot] merged 3 commits into
Conversation
There was a problem hiding this comment.
Approving. The change fixes what #721 asks for and leaves paths the push doesn't rename as they were.
What I checked
get_cloud_projectnow reads the local id before pushing. If the old directory is gone afterwards, it finds the project withProjectManager.get_project_by_id. A rename only happens inPushManager._push_project: a sanitized local name, or a replacement name from the cloud through its recursive call. That moves the whole directory with itsconfig.json, so the local id goes with it. Paths the push doesn't rename don't run the new lookup.- The second push in this method, for input that names a cloud project, pushes to the path
get_local_project_pathalready computed for that project, so the push doesn't rename it. It then reads the project by cloud id, not by path, so it doesn't have this bug.lean cloud pushdoesn't read the project path after pushing. get_project_by_idsearches the CLI root breadth-first and stops at project directories. A project at the top level is found before the search goes deeper into large folders such asdata/. The lookup runs only after a rename.- Assigning a
local-idbefore the push only adds that key to a config that lacks one. The push already does this for projects without a cloud id, and the local commands do it too.
Evidence
- The new parametrized test fails on
master'scloud_project_manager.pyand passes with this change. The file's other tests still pass. - CI is green on the head commit.
- I tested it end to end myself:
lean cloud backtest "<name with :>" --pushon a new project renamed the directory, created the cloud project, compiled it and ran the backtest to completion.- The same command on a project that already had a cloud id, after renaming it to an invalid name, renamed it locally and in the cloud, then backtested.
- A plain
--pushwith no rename still backtests.
Other repositories: none need an update.
Risk: risk:low. It's a 5-line bug fix that's easy to revert. Paths without a rename are unchanged, and the change is backed by a regression test that fails without it, green CI and end-to-end runs.
There was a problem hiding this comment.
Requesting changes at 591e2db. The normal rename cases are fixed, but recovering the pushed project through a local-ID write and a workspace-wide lookup introduces a blocking correctness/data-preservation problem.
Blocking finding
Please retain the final project path or cloud identity already known by the push instead of rediscovering it through get_project_by_id. I verified three consequences of the current approach:
- Unrelated configuration loss: with
Group/Unsafe:Projectand a siblingOtherApp/config.jsoncontaining JSON with a comment,lean cloud backtest 'Group/Unsafe:Project' --pushuploads and backtests successfully, but replaces the sibling configuration with an object containing onlylocal-id. - Wrong algorithm selected: copying an existing project, retaining its
local-id, removing itscloud-id, and pushing the copy asGroup/Unsafe:Copycreates the correct new cloud project, then compiles and backtests the original project. Tested end to end: the copy specified starting cash of 200,000, but the backtest ran the original with 100,000 and exited 0. - Previously working read-only push fails: an already-linked project with no
local-idand a read-only project directory pushes successfully on the base branch. This change raisesPermissionErrorcreatingconfig.json.lockbefore uploading.
The first two were reproduced end to end. All three were also compared using the real filesystem and real managers with only the API mocked: the base resolver preserves the unrelated configuration and stops instead of running the wrong project; its read-only push succeeds. Add regression coverage for these cases with the bounded identity-preserving fix.
Other verification
- CI is green on the reviewed head.
- Full suite, with the source checkout inherited by subprocesses:
PYTHONPATH="$PWD" python -m pytest -q— 2828 passed, 81 skipped. - Targeted resolver, project/push manager and cloud-command tests — 237 passed, 3 skipped.
- Both new rename cases fail with the base resolver and pass with this change.
python static_analysis.py— BUILD PASSED, five existing unused-import warnings.- The ordinary sanitized-name push, compilation and backtest also pass end to end.
Other repositories: none need an update.
Risk: risk:high, replacing risk:low, because the new recovery path can destroy unrelated configuration and select a different algorithm for execution. Green CI does not cover these reproduced failures.
|
Addressed the requested changes in f7e6a66. The resolver no longer looks the project up by local id, and it doesn't write a
The first two fail on 591e2db and on |
There was a problem hiding this comment.
Approving f7e6a66. My earlier approval of 591e2db missed what the other review found: the local-id lookup could rewrite unrelated configs, pick a copy's original, and break read-only pushes. This commit drops that approach for the smaller one that review asked for: the push reports where the project ended up, and the resolver reads the cloud id from there. This resolves all three problems.
What I checked
_push_projectreturns the final path on every successful exit: the normal end, after a local rename, and through the recursive call when the cloud assigns another name. Every other exit raises.get_cloud_projectreadspushed_project_paths[local_path]only whenpush_projectsreturned True. That only happens when every entry pushed, so the key is always set by this call, and it's the samePathobject the call passed in. An old entry from an earlier push is overwritten before it can be read.- The resolver no longer writes a
local-idand no longer searches the workspace. The second--pushbranch, for input that names a cloud project, reads by cloud id and is unchanged.lean cloud pushignores the new dict. The extra cost is one dict entry per pushed project.
Evidence
- CI is green on the head commit (Build and Regression Testing).
- The new tests fail where they should. With the PR's test module on
master's code, the two rename cases, the sibling-config case and the copy case fail, and they pass here. The read-only test passes on both, as the description says. - Full suite on the head merged with current
master: 2836 passed, 81 skipped. - I tested it end to end myself with the PR's CLI:
- I copied a pushed project to
Kr734:Copywith the samelocal-id, removed itscloud-idand set its cash to 200,000. I also added a siblingOther App/config.jsoncontaining a comment.lean cloud backtest "Kr734:Copy" --pushrenamed it toKr734 Copyand created a new cloud project. It backtested the copy itself (start equity 200,000), and the sibling config was byte-for-byte unchanged. - A plain
--pushwith no rename still backtests (start equity 100,000).
- I copied a pushed project to
Non-blocking: master now imports encryption_helper in tests/conftest.py (#735), so the same import in this test module is redundant (inline).
Other repositories: none need an update.
Risk: risk:low. It's a ~10-line fix confined to the push path, easy to revert, and pushes that don't rename work as before. The earlier risk:high was set on 591e2db for the workspace search, which this commit removes. The evidence is regression tests that fail without the fix, green CI and the end-to-end runs above.
A push renames the local project directory when its name is not valid or when the cloud assigns a different name. The cloud project resolver then read config.json from the old path, found no cloud id and failed, so `lean cloud backtest <name> --push` reported the project as missing. Find the project by its local id after the push when the directory moved. Closes #721 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… for it Looking the project up by local id after the push walked the whole CLI root, rewrote other configs it couldn't parse, could return another project sharing the same local id, and wrote a local id before pushing, which failed for read-only projects. The push now records where each pushed project ends up and the resolver reads the cloud id from there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f7e6a66 to
9ff4ab2
Compare
There was a problem hiding this comment.
Approving 9ff4ab2. Since my approval of f7e6a66, the branch was rebased onto master and one commit was added. That commit removes the redundant encryption_helper import from the test module, which was my only open point. tests/conftest.py on master now imports it before every module. lean/ is identical to f7e6a66, so my findings from that review still hold. The push records each project's final path, and the resolver reads the cloud id from it. Nothing searches the workspace or writes a local-id, which resolves all three problems raised on 591e2db.
Evidence
- CI is green on the head commit.
- The head merges cleanly with current
master. - The cloud component and command tests pass on the head: 169 passed.
- The end-to-end runs from my previous review still apply: the code they ran is unchanged.
Other repositories: none need an update.
Risk: risk:low, unchanged. It's a ~10-line fix confined to the push path and easy to revert. Pushes that don't rename work as before. It's backed by regression tests that fail without the fix, green CI and end-to-end runs.
There was a problem hiding this comment.
Approved at 9ff4ab2. The revised approach resolves my earlier blocking finding: it carries the actual final path out of the push instead of writing a local ID and searching the workspace. No new blocking findings.
What I verified
_push_projectreturns the final path after uploading, including through the recursive cloud-assigned rename.push_projectsrecords it under the original input path only after success. The resolver reads that entry only after a successful singleton push, so neither failed pushes nor entries from earlier calls can supply a stale result.- The resolver no longer scans unrelated configurations or adds a local ID before pushing. The tests cover configuration preservation, copies sharing a local ID, and read-only linked projects. Existing failure handling and the cloud-ID resolver branch are unchanged.
Evidence
- Head CI: Build and Regression Testing succeeded.
PYTHONPATH="$PWD" python -m pytest -q: 2836 passed, 81 skipped.- Running the PR's resolver test module against current
masterproduces 4 failures, 4 passes: both rename cases, configuration-preservation and copied-project resolution fail without the fix; the read-only case passes on both. python static_analysis.py: BUILD PASSED, with the five existing unused-import warnings.- Tested end to end: a renamed copy sharing its original's local ID backtested its own code with 200,000 start equity. The original's configuration and an unrelated sibling configuration containing a comment remained byte-for-byte unchanged. An ordinary non-renaming
--pushalso compiled and backtested successfully, with 100,000 start equity.
Other repositories: none need an update.
Risk: risk:low retained. This is a small, reversible fix confined to retaining the successful push's final path. It removes the previously reported configuration-loss/wrong-project recovery mechanism, leaves ordinary pushes unchanged, and is backed by regression tests, green CI and end-to-end verification.
Closes #721
What changed and why
lean cloud <command> <project> --pushpushes the local project, then reads itsconfig.jsonto get the cloud id. When the push renames the project directory, the resolver still read the old path. This happens when the name isn't valid locally (for exampleUnsafe:ProjectbecomesUnsafe Project) or when the cloud assigns a different name. The resolver found no cloud id and raised, andlean cloud backtestreported that the project wasn't found, even though the push had succeeded.PushManager._push_projectnow returns the path where the project is after the push. The recursive call for a cloud-assigned name passes that path through.PushManager.push_projectsrecords each pushed project's final path inpushed_project_paths, keyed by the path it was given. Its return value is unchanged.CloudProjectManager.get_cloud_projectreads the cloud id from the recorded final path.The resolver doesn't search the workspace or write a local id. Other project configs are never touched, and a copy that shares its original's
local-idresolves to its own cloud project. A linked project in a read-only directory pushes the way it does onmaster. Pushes that don't rename work as before.The first commit found the project by its local id instead. Review showed that this rewrote other configs it couldn't parse, could pick a copy's original, and broke read-only pushes. The second commit replaces it.
Tests
New tests in
tests/components/cloud/test_cloud_project_manager.pyuse the real push manager and project config manager with a mocked API:test_get_cloud_project_follows_project_renamed_by_push: a sanitized name (Unsafe:Project) and a replacement name assigned by the cloud. Both fail onmaster.test_get_cloud_project_leaves_other_project_configs_untouched_when_push_renames_project: a siblingconfig.jsonholding JSON with a comment stays byte for byte the same.test_get_cloud_project_returns_pushed_copy_sharing_the_local_id_of_its_original: the copy's new cloud project is returned, not the original's.test_get_cloud_project_pushes_read_only_linked_project_without_local_id: the push succeeds as a non-root user with a read-only project directory, and nolocal-idis written.On
master, the two rename cases, the sibling-config test and the copy test fail; the read-only test passes. On the first commit of this PR, the last three fail. All of them pass now.PYTHONPATH=$PWD python -m pytest -q, rebased on currentmaster: 2836 passed, 81 skipped.python static_analysis.py: build passed, with the 5 unused-import warnings thatmasteralready has.lean cloud backtest "<name with :>" --pushrenamed the directory, created the cloud project, then compiled and backtested it. Onmasterit stops after the push withNo project with the given name or id ... found.Copy:721, with the samelocal-idas its pushed original, itscloud-idremoved and starting cash changed to 200,000, was pushed and backtested with--push. The backtest ran the copy (start equity 200,000), and a siblingOther App/config.jsoncontaining a comment was left unchanged.